<?php
namespace app\common;

use AlibabaCloud\Client\AlibabaCloud;
use AlibabaCloud\Client\Exception\ClientException;
use AlibabaCloud\Client\Exception\ServerException;

class Sms
{

  

  public function getCode($mobile ='',$num = 0)
  {
    //SMS_182880053 验证码${code}，您正在登录，若非本人操作，请勿泄露。
    $sms = array();
    $sms['code'] = $num;
    $arr = [
            'query' => [
              'RegionId' => "cn-hangzhou",
              // 'SignName' => '棵云',
              'SignName' => '云客易购',
              'PhoneNumbers' => $mobile,
              'TemplateCode' => 'SMS_182880053',
              'TemplateParam' => json_encode($sms),
            ],
        ];
    return $this->send($mobile,$arr);
    # code...
  }

  public function getChangeCode($mobile ='',$num = 0)
  {
    //SMS_182880053 验证码${code}，您正在登录，若非本人操作，请勿泄露。
    $sms = array();
    $sms['code'] = $num;
    $arr = [
            'query' => [
              'RegionId' => "cn-hangzhou",
              // 'SignName' => '棵云',
              'SignName' => '云客易购',
              'PhoneNumbers' => $mobile,
              'TemplateCode' => 'SMS_182880049',
              'TemplateParam' => json_encode($sms),
            ],
        ];
    return $this->send($mobile,$arr);
    # code...
  }

  public function send($mobile = '',$arr = array())
  {
    AlibabaCloud::accessKeyClient('LTAI4FcNK8v7fcRNxbzQQTZr', 'eOqzpw50BWMPko07bklddBXdFal8ZK')
                        ->regionId('cn-hangzhou')
                        ->asDefaultClient();

    try {
        $result = AlibabaCloud::rpc()
          ->product('Dysmsapi')
          // ->scheme('https') // https | http
          ->version('2017-05-25')
          ->action('SendSms')
          ->method('POST')
          ->options($arr)
          ->request();
      // print_r($result->toArray());
    } catch (ClientException $e) {
      echo $e->getErrorMessage() . PHP_EOL;
    } catch (ServerException $e) {
      echo $e->getErrorMessage() . PHP_EOL;
    }
  }


  public function doReg($value='')
  {
    # code...
  }
}